<?php
/**
 * 兄弟姐妹資料檔
 * @author cik
 *
 */
class Default_Model_Upgrade_StudBrotherSister extends Default_Model_Upgrade_Core
{
    protected $_table = 'stud_brother_sister';
    protected $_targetTable = array('student_sibling');

    public function upgrade()
    {
        if ($this->isUpgrade())
        return 'isUpgrde';
        else {
            $query = "SELECT COUNT(*)  AS cc FROM student_sibling";
            $res = $this->_newdbPdo->query($query)->fetch();
            $hasData = $res['cc'];

            $query = "SELECT a.* FROM  stud_brother_sister a , stud_base b WHERE a.student_sn=b.student_sn";
            $res = $this->_sfs3Pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
            foreach($res as $row) {
                $arr = array();

                $arr['student_sn'] = $row['student_sn'];
                $arr['name'] = $this->iconv($row['bs_name']);
                $arr['calling'] = $row['bs_calling'];
                $arr['born_year'] = $row['bs_birthyear'];
                if ($hasData) {
                    $find = $this->_newdbPdo->query("SELECT student_sn FROM student_sibling
				  WHERE  student_sn ='{$arr['student_sn']}'
				  AND name ='{$arr['name']}'
				  AND calling ='{$arr['calling']}'
				  ");
                    if ($find)
                    continue;
                }
                $this->fromArray('student_sibling',$arr);
            }
            $log['memo'] = 'stud_brother_sister  升級';
            $log['upgrade_time']	= date("Y-m-d h:i:s");

            $this->finishUpgrade($log);
        }
    }
}
